 

var AppLestUrl = getApp().globalData.wxurl;

function getReq(url,data,header,cb) {
  wx.showLoading({
    title: '加载中',
  }) 
  wx.request({
    url: AppLestUrl + url,
    method: 'GET',
    header: header,
    data:data,
    success: function (res) {
      wx.hideLoading();
      var JsonData = res.data;
      var JsonCode = res.statusCode;
      return typeof cb == "function" && cb(JsonData, JsonCode);
    },
    fail: function () {
      wx.hideLoading();
      wx.showModal({
        title: '网络错误',
        content: '网络出错，请刷新重试',
        showCancel: false
      })
      return typeof cb == "function" && cb(false)
    }
  })
}

function postReq(url, data, header,cb) {
  wx.showLoading({
    title: '提交中',
  }) 
    wx.request({
      url: AppLestUrl + url,
      header: header,
      data: data,
      method: 'POST',
      success: function (res) {
        wx.hideLoading(); 
        var JsonData = res.data;
        var JsonCode = res.statusCode;
        return typeof cb == "function" && cb(JsonData, JsonCode)
      },
      fail: function () {
        wx.hideLoading();
        wx.showModal({
          title: '网络错误',
          content: '网络出错，请刷新重试',
          showCancel: false
        })
        return typeof cb == "function" && cb(false)
      }
    })

}
module.exports = {
  getReq: getReq,
  postReq: postReq, 
}   